unit MT4APIUnit;

interface

uses DataTypes;

type

  TCssToSql=procedure(CssFile:PChar; QuoteTypeId:Integer; SqlFile:PChar);
  TLoadQuotes=function(QuoteTypeId:Integer; DateFrom:TDateTime; DateTo:TDateTime; var Date,Open,High,Low,Close:TArrOfDouble; var Volume:TArrOfInteger):Integer;

  TMT4API=class
  public
    procedure CssToSql(CssFile:PChar; QuoteTypeId:Integer; SqlFile:PChar);
    function Load(QuoteTypeId:Integer; DateFrom:TDateTime; DateTo:TDateTime; var Date,Open,High,Low,Close:TArrOfDouble; var Volume:TArrOfInteger):Integer;
  end;

implementation

uses  Windows,Dialogs;

procedure TMT4API.CssToSql(CssFile:PChar; QuoteTypeId:Integer; SqlFile:PChar);
var
  hndDLLHandle: THandle;
  method: TCssToSql;
begin
  try
    hndDLLHandle := LoadLibrary ( 'MT4API.dll' );
    if hndDLLHandle <> 0 then begin
      @method := getProcAddress ( hndDLLHandle, 'CssToSql' );
      if addr ( method ) <> nil then begin
        method(CssFile,QuoteTypeId,SqlFile);
      end else showMessage ( 'Function not exists...' );
    end else
      showMessage ( 'DLL not found...' );
  finally
    freeLibrary ( hndDLLHandle );
  end;
end;

function TMT4API.Load(QuoteTypeId:Integer; DateFrom:TDateTime; DateTo:TDateTime; var Date,Open,High,Low,Close:TArrOfDouble; var Volume:TArrOfInteger):Integer;
var
  hndDLLHandle: THandle;
  method: TLoadQuotes;
begin
  Result:=0;
  try
    hndDLLHandle := LoadLibrary ( 'MT4API.dll' );
    if hndDLLHandle <> 0 then begin
      @method := getProcAddress ( hndDLLHandle, 'LoadQuotes' );
      if addr ( method ) <> nil then begin
        Result:=method(QuoteTypeId,DateFrom,DateTo,Date,Open,High,Low,Close,Volume);
      end else showMessage ( 'Function not exists...' );
    end else
      showMessage ( 'DLL not found...' );
  finally
    freeLibrary ( hndDLLHandle );
  end;
end;

end.
